< previous page page_291 next page >

Page 291
(table continued from previous page)
BIT #3BIT #2BIT #1BIT #0HEX DIGIT
01004
01015
01106
01117
10008
10019
1010A
1011B
1100C
1101D
1110E
1111F

Now the 16-bit binary number 1010 1011 1100 1101 becomes ABCD. If you have a 32-bit number to deal with, it's a lot more pleasant to write it as 049AB159 than 00000100010101011000101011001. In fact, it's so much more pleasant that no programmer in his right mind ever uses binary numbers. We use nibbles, where each digit represents four bits. Of course, we don't call it that. Since each digit represents four bits and thus 16 possible values (0F), we call it hexadecimal (for base 16). In Visual Basic, we give it a prefix &H to indicate hexadecimal; thus we write hex AB15 as &HAB15. A C programmer would use the prefix Ox to indicate hexadecimal, so the same number would appear as 0xAB15.
Bytes
If you've followed along so far, relaxthe hardest part is over. You know about bits. You know that the more bits you have, the more possible values they can take on. A single bit can have one of two values. Four bits can have a total of 16 values. Eight bits can have a total of 256 values. The number of possible values is, in fact 2 , where N is the number of bits (in English, this means that every time you add a bit, the number of possible values doubles).
Eight bits are called a byte. Visual Basic actually has a Byte data type, which is, in fact, the only unsigned data type that Visual Basic supports natively. This means that a byte value can range from 0 to 255.
Bytes are the fundamental unit of measurement for computer memory. What does this mean?
Figure T2-1 shows how memory was organized on the first 8-bit microprocessors. Memory was divided into 65,536 bytes (64K) of memory. Each byte could be addressed individually by the microprocessor. If you wanted to check the value of a particular bit inside a byte, you had to load the entire byte and check the value of that byte to determine whether the bit was set. The process of

 
< previous page page_291 next page >